<template>
	<view class="recharge-history-page">
		<navigation :navigationMsg="navigationMsg"></navigation>
		<view class="main">
			<view class="wallet-box">
				<view class="box1">
					<p>钱包余额</p>
					<p>{{userInfo.money}}</p>
				</view>
				<view class="box2"></view>
				<view class="box3">
					<p>累计充值金额</p>
					<p>****</p>
				</view>
			</view>
			<view class="list">
				<view class="list-item" v-for="(item,index) in reversedRechargeList" :key="index">
					<view class="left">
						<view class="money">￥{{item.money}}</view>
						<view class="time">{{item.formattedTime}}</view>
					</view>
					<view class="right">
						<view class="manner">支付宝</view>
						<view class="status">充值成功</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		http
	} from '@/api/index.js'
	import navigation from '../../../../components/navigation.vue';
	export default {
		data() {
			return {
				navigationMsg: {
					title: "充值记录"
				},
				//充值记录
				rechargeList: [],
				//用户信息
				userInfo: {},
				//背景色
				bgColor: "#fff",
				//文本色
				textColor: "#2A2D2E"
			}
		},
		components: {
			navigation
		},
		onShow() {
			this.getUserInfo()
			this.getRechargeRecordes()
			this.getSetting()
		},
		computed: {
			//转换时间
			formattedTimes() {
				return this.rechargeList.map((item, index) => {
					const date = new Date(item.create_time * 1000)
					const year = date.getFullYear();
					const month = (date.getMonth() + 1).toString().padStart(2, '0');
					const day = date.getDate().toString().padStart(2, '0');
					const hours = date.getHours().toString().padStart(2, '0');
					const minutes = date.getMinutes().toString().padStart(2, '0');
					const seconds = date.getSeconds().toString().padStart(2, '0');
					const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
					return {
						...item,
						formattedTime
					};
				})
			},
			//倒叙渲染
			reversedRechargeList() {
				return [...this.formattedTimes].reverse();
			},
		},
		methods: {
			//获取网站配置
			getSetting() {
				http.post('/api/index/getSetting').then(res => {
					document.documentElement.style.setProperty('--bg-color', res.theme_color);
					document.documentElement.style.setProperty('--text-color', res.font_color);
				}).catch(err => {
					console.log(err);
				})
			},
			//获取会员资料
			getUserInfo() {
				http.post('/api/account/getUserInfo').then(res => {
					this.userInfo = res
				}).catch(err => {

					// console.log(this.userInfo);
				})
			},
			//获取充值记录
			getRechargeRecordes() {
				http.post('/api/recharge/rechargeRecordes', {
					limit: 50
				}).then(res => {
					this.rechargeList = res.data
				}).catch(err => {
					// console.log(err.data.data.data);

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	:root {
		--bg-color: ;
		--text-color: ;
	}

	.recharge-history-page {
		width: 100%;
		height: 100vh;
		background-color: var(--bg-color);

		.main {
			width: 100%;
			height: calc(100% - 100rpx);
			overflow: hidden;

			.wallet-box {
				width: 90%;
				height: 150rpx;
				background-color: #2c2c31;
				margin: auto;
				margin-top: 30rpx;
				border-radius: 30rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;

				.box1,
				.box3 {
					display: flex;
					flex-direction: column;
					color: white;
					justify-content: space-evenly;

					>p:nth-child(1) {
						font-size: 30rpx;
						color: #ccc;
					}

					>p:nth-child(2) {
						font-weight: bold;
						font-size: 36rpx;
					}
				}

				.box1 {
					width: 35%;
					height: 100%;
				}

				.box2 {
					width: 1px;
					height: 40%;
					background-color: #ccc;
				}

				.box3 {
					width: 35%;
					height: 100%;
				}
			}

			.list {
				width: 90%;
				height: calc(100% - 210rpx);
				margin: auto;
				margin-top: 30rpx;
				overflow-y: scroll;
				border-radius: 30rpx;

				.list-item {
					width: 100%;
					height: 140rpx;
					background-color: var(--bg-color);
					color: var(--text-color);
					display: flex;
					justify-content: space-between;
					align-items: center;

					.left {
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-evenly;
						margin-left: 20rpx;

						.money {
							font-weight: bold;
							font-size: 34rpx;
						}

						.time {
							font-size: 26rpx;
							color: #949494;
						}
					}

					.right {
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-evenly;
						margin-right: 20rpx;
						text-align: right;

						.manner {
							font-size: 26rpx;
							color: #949494;
						}

						.status {
							font-size: 28rpx;
						}
					}
				}

				.list-item:not(:last-child) {
					border-bottom: 1px solid #e5e5e5;
				}

				.list-item:last-child {
					border-radius: 0px 0px 30rpx 30rpx;
				}
			}
		}
	}
</style>